package me.principality.webapp

import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import springfox.documentation.builders.ApiInfoBuilder
import springfox.documentation.builders.PathSelectors
import springfox.documentation.builders.RequestHandlerSelectors
import springfox.documentation.oas.annotations.EnableOpenApi
import springfox.documentation.service.ApiInfo
import springfox.documentation.service.Contact
import springfox.documentation.spi.DocumentationType
import springfox.documentation.spring.web.plugins.Docket

/**
 * 请求地址：/swagger-ui/index.html
 */
@Configuration
@EnableOpenApi
class SwaggerConfiguration {
    @Bean
    fun docket(): Docket {
        return Docket(DocumentationType.OAS_30)
            .apiInfo(apiInfo()).enable(true)
            .select() //apis： 添加swagger接口提取范围
            .apis(RequestHandlerSelectors.basePackage("me.principality.webapp.controller")) //.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
            .paths(PathSelectors.any())
            .build()
    }

    private fun apiInfo(): ApiInfo {
        return ApiInfoBuilder()
            .title("XX项目接口文档")
            .description("XX项目描述")
            .contact(Contact("作者", "作者URL", "作者Email"))
            .version("1.0")
            .build()
    }
}